package de.msspp.webservice;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class LocationsOverlay extends ItemizedOverlay<OverlayItem> 
{	
	private Context context;
	private ArrayList<OverlayItem> mOverlays;

	public LocationsOverlay(Drawable arg0) 
	{
		super(boundCenterBottom(arg0));
		mOverlays = new ArrayList<OverlayItem>();
	}
	
	public LocationsOverlay(Drawable arg0, Context c)
	{
		super(boundCenterBottom(arg0));
		context = c;
		mOverlays = new ArrayList<OverlayItem>();
	}

	@Override
	protected OverlayItem createItem(int i) 
	{
		return mOverlays.get(i);
	}

	@Override
	public int size() 
	{
		return mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index)
	{
		//Show little DetailDialog
		OverlayItem item = mOverlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(context);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}
	
	public void addOverlay(OverlayItem item)
	{
		mOverlays.add(item);
		populate();
	}
	
	public void clear()
	{
		mOverlays.clear();
		populate();
	}
}
